/*
 * Copyright (c) 田梓萱 2021-2022.
 * All Rights Reserved.
 * All codes are protected by China's regulations on the protection of computer software, and infringement must be investigated.
 * 版权所有 (c) 田梓萱 2021-2022.
 * 所有代码均受中国《计算机软件保护条例》保护，本项目已获得软著.
 */

package com.xcl.calculator.slice.BianQian.second;

import com.huawei.agconnect.crash.AGConnectCrash;
import com.litesuits.orm.db.assit.QueryBuilder;
import com.litesuits.orm.db.assit.WhereBuilder;
import com.xcl.calculator.DataANet.Sharmes;
import com.xcl.calculator.DataANet.Showmes;
import com.xcl.calculator.Dialog.MyToastDialog;
import com.xcl.calculator.Preference_RW;
import com.xcl.calculator.ResourceTable;
import com.xcl.calculator.XLog;
import com.xcl.calculator.slice.BianQian.Contactor;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.aafwk.content.Operation;
import ohos.agp.components.Component;
import ohos.agp.components.LayoutScatter;
import ohos.agp.components.ListContainer;
import ohos.agp.components.Text;
import ohos.agp.utils.LayoutAlignment;
import ohos.agp.window.dialog.CommonDialog;
import ohos.agp.window.service.WindowManager;
import ohos.data.distributed.common.KvManagerConfig;
import ohos.data.distributed.common.KvManagerFactory;
import ohos.distributedhardware.devicemanager.DeviceInfo;
import ohos.hiviewdfx.HiLog;
import ohos.hiviewdfx.HiLogLabel;
import ohos.multimodalinput.event.KeyEvent;
import ohos.multimodalinput.event.MmiPoint;
import ohos.multimodalinput.event.TouchEvent;

import java.util.ArrayList;
import java.util.List;

import static com.xcl.calculator.MyApplication.liteOrm;

/**
 * The type Bian qian show ability slice.
 *
 * @author Xcl
 * @date 2021 /1/12
 * @package com.xcl.calculator.slice.BianQian.second
 */
public class BianQianShowAbilitySlice extends AbilitySlice implements ContactProvider1.AdapterClickListener, Component.TouchEventListener {
    /**
     * The constant label.
     */
    private static final HiLogLabel label = new HiLogLabel(HiLog.LOG_APP, 0x00234, "BianQianShowAbilitySlice");
    /**
     * The constant text.
     */
    private static String text = null;
    /**
     * The constant text1.
     */
    private static String text1 = null;
    /**
     * The Starx.
     */
    private float starx;
    /**
     * The Stary.
     */
    private float stary;
    /**
     * The Endx.
     */
    private float endx;
    /**
     * The Endy.
     */
    private float endy;
    /**
     * The A 6.
     */
    private int a6 = 999;
    /**
     * The A 8.
     */
    private int a8 = 999;
    /**
     * The Contact adapter.
     */
    private ContactProvider1 contactAdapter;
    /**
     * The Contact arrays.
     */
    private List<Contactor> contactArrays;

    /**
     * 插入
     *
     * @param id     the id
     * @param name   the name
     * @param gender the gender
     */
    private static void insert(long id, String name, String gender) {
        try {
            Showmes s1 = new Showmes();
            s1.setId(id);
            s1.setTitle(name);
            s1.setMessage(gender);
            liteOrm.save(s1);
        } catch (Exception e) {
            AGConnectCrash.getInstance().recordException(e);
            XLog.error(label, e.getMessage());
        }
    }

    /**
     * 更新
     *
     * @param a1 the a 1
     * @param a2 the a 2
     */
    private static void update(String a1, String a2) {
        try {
            List<Showmes> books = liteOrm.query(new QueryBuilder<Showmes>(Showmes.class)
                    .columns(new String[]{"id", "title", "message"})
                    .distinct(true)
                    .whereEquals("title", a1));
            Showmes s1 = new Showmes();
            s1.setId(books.get(0).getId());
            s1.setTitle(a1);
            s1.setMessage(a2);
            liteOrm.save(s1);
        } catch (Exception e) {
            AGConnectCrash.getInstance().recordException(e);
            XLog.error(label, e.getMessage());
        }
    }

    /**
     * 插入
     *
     * @param id     the id
     * @param name   the name
     * @param gender the gender
     */
    private static void insert1(long id, String name, String gender) {
        try {
            Sharmes s3 = new Sharmes();
            s3.setId(id);
            s3.setTitle(name);
            s3.setMessage(gender);
            liteOrm.save(s3);
        } catch (Exception e) {
            AGConnectCrash.getInstance().recordException(e);
            XLog.error(label, e.getMessage());
        }
    }

    /**
     * 更新
     *
     * @param a1 the a 1
     * @param a2 the a 2
     */
    private static void update1(String a1, String a2) {
        try {
            List<Sharmes> books = liteOrm.query(new QueryBuilder<Sharmes>(Sharmes.class)
                    .columns(new String[]{"id", "title", "message"})
                    .distinct(true)
                    .whereEquals("title", a1));
            Sharmes s5 = new Sharmes();
            s5.setId(books.get(0).getId());
            s5.setTitle(a1);
            s5.setMessage(a2);
            liteOrm.save(s5);
        } catch (Exception e) {
            AGConnectCrash.getInstance().recordException(e);
            XLog.error(label, e.getMessage());
        }
    }

    /**
     * 开始
     *
     * @param intent the intent
     */
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        try {
            XLog.pd_pd = Preference_RW.ff7_r();
            this.getWindow().addFlags(WindowManager.LayoutConfig.MARK_ALLOW_EXTEND_LAYOUT);
            ohos.data.distributed.device.DeviceInfo localDeviceInfo = KvManagerFactory.getInstance()
                    .createKvManager(new KvManagerConfig((this))).getLocalDeviceInfo();
            int localDeviceType = Integer.parseInt(localDeviceInfo.getType());
            if (localDeviceType == DeviceInfo.DeviceType.PHONE.value()) {
                this.setUIContent(ResourceTable.Layout_bianqianshow_0m);
                XLog.info(label, "当前设备类型为手机");
            } else if (localDeviceType == DeviceInfo.DeviceType.TABLET.value()) {
                this.setUIContent(ResourceTable.Layout_bianqianshow_0t);
                XLog.info(label, "当前设备类型为平板");
            } else {
                XLog.warn(label, "暂不支持您的设备:(" + localDeviceInfo.getType() + ")");
                this.terminateAbility();
            }

            Component component1 = this.findComponentById(ResourceTable.Id_listContainer1);
            component1.setBindStateChangedListener(new Component.BindStateChangedListener() {
                @Override
                public void onComponentBoundToWindow(Component component) {
                    component.setTouchFocusable(true);
                    component.setVibrationEffectEnabled(true);
                    component.requestFocus();
                }

                @Override
                public void onComponentUnboundFromWindow(Component component) {
                }
            });
            this.findComponentById(ResourceTable.Id_bianqianshow0).setTouchEventListener(this);
            this.initList();
            this.findComponentById(ResourceTable.Id_addContact1).setClickedListener(new Component.ClickedListener() {
                @Override
                public void onClick(Component component) {
                    BianQianShowAbilitySlice.this.showDialog(666, null, null, new ContactComponent1.DialogCallBack() {
                        @Override
                        public void result(String messages, String titles) {
                            BianQianShowAbilitySlice.this.query(messages);
                            if (Preference_RW.ff3_r() == 0) {
                                long a = Preference_RW.ff3_r() + 1;
                                BianQianShowAbilitySlice.insert(a, titles, messages);
                                a++;
                                Preference_RW.ff3_w(a);
                            } else {
                                BianQianShowAbilitySlice.this.query(titles);
                                if (BianQianShowAbilitySlice.this.a6 == 666)
                                    BianQianShowAbilitySlice.update(titles, messages);
                                else if (BianQianShowAbilitySlice.this.a6 == 999) {
                                    long a = Preference_RW.ff3_r() + 1;
                                    BianQianShowAbilitySlice.insert(a, titles, messages);
                                    a++;
                                    Preference_RW.ff3_w(a);
                                } else XLog.warn(BianQianShowAbilitySlice.label, "不可能！");
                            }
                            BianQianShowAbilitySlice.this.contactArrays.add(new Contactor(messages, titles));
                            BianQianShowAbilitySlice.this.ShowDialog1("添加成功!");
                            BianQianShowAbilitySlice.this.contactAdapter.notifyDataSetItemInserted(BianQianShowAbilitySlice.this.contactAdapter.getCount());
                        }
                    });
                }
            });
            this.getUITaskDispatcher().delayDispatch(this::queryContact, 100L);
        } catch (Exception e) {
            AGConnectCrash.getInstance().recordException(e);
            XLog.error(label, e.getMessage());
        }
    }

    /**
     * 展示数据
     *
     * @param text1 the text 1
     */
    private void ShowDialog(String text1) {
        try {
            ohos.data.distributed.device.DeviceInfo localDeviceInfo = KvManagerFactory.getInstance()
                    .createKvManager(new KvManagerConfig((this))).getLocalDeviceInfo();
            int localDeviceType = Integer.parseInt(localDeviceInfo.getType());
            if (localDeviceType == DeviceInfo.DeviceType.PHONE.value()) {
                new MyToastDialog(this.getContext(), text1, ResourceTable.Graphic_extoast_framem, 36, 25)
                        .setDuration(120)
                        .setAlignment(LayoutAlignment.BOTTOM)
                        .setOffset(0, 100)
                        .show();
                XLog.info(label, "当前设备类型为手机");
            } else if (localDeviceType == DeviceInfo.DeviceType.TABLET.value()) {
                new MyToastDialog(this.getContext(), text1, ResourceTable.Graphic_extoast_framet, 43, 37)
                        .setDuration(120)
                        .setAlignment(LayoutAlignment.BOTTOM)
                        .setOffset(0, 100)
                        .show();
                XLog.info(label, "当前设备类型为平板");
            } else {
                XLog.warn(label, "暂不支持您的设备:(" + localDeviceInfo.getType() + ")");
                this.terminateAbility();
            }
        } catch (Exception e) {
            AGConnectCrash.getInstance().recordException(e);
            XLog.error(label, e.getMessage());
        }
    }

    /**
     * 展示数据1
     *
     * @param text1 the text 1
     */
    private void ShowDialog1(String text1) {
        try {
            ohos.data.distributed.device.DeviceInfo localDeviceInfo = KvManagerFactory.getInstance()
                    .createKvManager(new KvManagerConfig((this))).getLocalDeviceInfo();
            int localDeviceType = Integer.parseInt(localDeviceInfo.getType());
            if (localDeviceType == DeviceInfo.DeviceType.PHONE.value()) {
                new MyToastDialog(this.getContext(), text1, ResourceTable.Graphic_xtoast_framem, 36, 25)
                        .setDuration(120)
                        .setAlignment(LayoutAlignment.BOTTOM)
                        .setOffset(0, 100)
                        .show();
                XLog.info(label, "当前设备类型为手机");
            } else if (localDeviceType == DeviceInfo.DeviceType.TABLET.value()) {
                new MyToastDialog(this.getContext(), text1, ResourceTable.Graphic_xtoast_framet, 43, 37)
                        .setDuration(120)
                        .setAlignment(LayoutAlignment.BOTTOM)
                        .setOffset(0, 100)
                        .show();
                XLog.info(label, "当前设备类型为平板");
            } else {
                XLog.warn(label, "暂不支持您的设备:(" + localDeviceInfo.getType() + ")");
                this.terminateAbility();
            }
        } catch (Exception e) {
            AGConnectCrash.getInstance().recordException(e);
            XLog.error(label, e.getMessage());
        }
    }


    /**
     * 初始化
     */
    private void initList() {
        try {
            Component component = this.findComponentById(ResourceTable.Id_listContainer1);
            ListContainer listContainer;
            if (component instanceof ListContainer) {
                listContainer = (ListContainer) component;
                this.contactArrays = new ArrayList<>(0);
                this.contactAdapter = new ContactProvider1(this, this.contactArrays);
                listContainer.setItemProvider(this.contactAdapter);
                listContainer.enableScrollBar(Component.AXIS_Y, true);
                listContainer.setScrollbarRoundRect(true);
                listContainer.setScrollbarRadius(component.getScrollbarThickness() / 2);
                this.contactAdapter.setAdapterClickListener1(this);
            }
        } catch (Exception e) {
            AGConnectCrash.getInstance().recordException(e);
            XLog.error(label, e.getMessage());
        }
    }

    /**
     * 初始化
     */
    private void queryContact() {
        try {
            //long book = liteOrm.queryCount(new QueryBuilder<Showmes>(Showmes.class));
            List<Showmes> books = liteOrm.query(new QueryBuilder<Showmes>(Showmes.class)
                    .columns(new String[]{"id", "title", "message"})
                    .distinct(true)
                    .whereGreaterThan("id", 0)
                    .whereAppendAnd()
                    .whereLessThan("id", (Preference_RW.ff3_r() + 1)));
            for (int i = 0; i < books.size(); i++) {
                this.contactArrays.add(new Contactor(books.get(i).getMessage(), books.get(i).getTitle()));
                this.contactAdapter.notifyDataChanged();
            }
        } catch (Exception e) {
            AGConnectCrash.getInstance().recordException(e);
            XLog.error(label, e.getMessage());
        }
    }

    /**
     * 数据展示
     *
     * @param bbb            the bbb
     * @param titles         the titles
     * @param messages       the messages
     * @param dialogCallBack the dialog call back
     */
    private void showDialog(int bbb, String titles, String messages, ContactComponent1.DialogCallBack dialogCallBack) {
        try {
            CommonDialog commonDialog = new CommonDialog(this);
            ohos.data.distributed.device.DeviceInfo localDeviceInfo = KvManagerFactory.getInstance()
                    .createKvManager(new KvManagerConfig((this))).getLocalDeviceInfo();
            int device = Integer.parseInt(localDeviceInfo.getType());
            ContactComponent1 component1 = new ContactComponent1(this, device);
            component1.initData(titles, messages);
            component1.setDialogCallBack(new ContactComponent1.DialogCallBack() {
                @Override
                public void result(String titlesInput, String messagesInput) {
                    component1.setTextFiledNormalGraphic();
                    if (titlesInput.isEmpty() || titlesInput.trim().isEmpty()) {
                        BianQianShowAbilitySlice.this.ShowDialog("信息必填");
                        component1.setTextFiledErrorGraphic(1);
                        return;
                    }
                    if (messagesInput.isEmpty() || messagesInput.trim().isEmpty()) {
                        BianQianShowAbilitySlice.this.ShowDialog("标题必填");
                        component1.setTextFiledErrorGraphic(2);
                        return;
                    }
                    if (bbb == 666) {
                        BianQianShowAbilitySlice.this.query(messagesInput);
                        if (BianQianShowAbilitySlice.this.a6 == 666) {
                            BianQianShowAbilitySlice.this.ShowDialog("标题重复");
                            component1.setTextFiledErrorGraphic(2);
                            return;
                        }
                    }
                    if (dialogCallBack != null) dialogCallBack.result(titlesInput, messagesInput);
                    commonDialog.remove();
                }
            });
            commonDialog.setContentCustomComponent(component1);
            commonDialog.show();
        } catch (Exception e) {
            AGConnectCrash.getInstance().recordException(e);
            XLog.error(label, e.getMessage());
        }
    }

    /**
     * 编辑
     *
     * @param position the position
     */
    @Override
    public void edit(int position) {
        try {
            Contactor contactor = this.contactArrays.get(position);
            this.showDialog(999, contactor.getTitles(), contactor.getMessages(), new ContactComponent1.DialogCallBack() {
                @Override
                public void result(String titles, String messages) {
                    BianQianShowAbilitySlice.this.query(messages);
                    if (BianQianShowAbilitySlice.this.a6 == 666) {
                        BianQianShowAbilitySlice.update(messages, titles);
                        BianQianShowAbilitySlice.this.contactArrays.set(position, new Contactor(titles, messages));
                        BianQianShowAbilitySlice.this.contactAdapter.notifyDataSetItemChanged(position);
                    } else if (BianQianShowAbilitySlice.this.a6 == 999) {
                        long a = Preference_RW.ff3_r();
                        BianQianShowAbilitySlice.insert(a, messages, titles);
                        a++;
                        Preference_RW.ff3_w(a);
                        BianQianShowAbilitySlice.this.contactArrays.add(new Contactor(titles, messages));
                        BianQianShowAbilitySlice.this.contactAdapter.notifyDataSetItemInserted(BianQianShowAbilitySlice.this.contactAdapter.getCount());
                    } else XLog.warn(BianQianShowAbilitySlice.label, "不可能！");
                    BianQianShowAbilitySlice.this.ShowDialog1("编辑成功!");
                }
            });
        } catch (Exception e) {
            AGConnectCrash.getInstance().recordException(e);
            XLog.error(label, e.getMessage());
        }
    }

    /**
     * 删除
     *
     * @param position the position
     */
    @Override
    public void delete(int position) {
        try {
            CommonDialog commonDialog = new CommonDialog(this);
            ohos.data.distributed.device.DeviceInfo localDeviceInfo = KvManagerFactory.getInstance()
                    .createKvManager(new KvManagerConfig((this))).getLocalDeviceInfo();
            int localDeviceType = Integer.parseInt(localDeviceInfo.getType());
            if (localDeviceType == DeviceInfo.DeviceType.PHONE.value()) {
                Component component = LayoutScatter.getInstance(this.getContext())
                        .parse(ResourceTable.Layout_bianqian_3m, null, true);
                //commonDialog.setAutoClosable(true);
                commonDialog.setSize(850, 850);
                commonDialog.setContentCustomComponent(component);
                component.findComponentById(ResourceTable.Id_bqsure).setClickedListener(new Component.ClickedListener() {
                    @Override
                    public void onClick(Component v) {
                        if (position > BianQianShowAbilitySlice.this.contactArrays.size() - 1) {
                            BianQianShowAbilitySlice.this.ShowDialog("要删除的元素不存在");
                            return;
                        }
                        Contactor contactor = BianQianShowAbilitySlice.this.contactArrays.get(position);
                        liteOrm.delete(new WhereBuilder(Showmes.class)
                                .equals("title", contactor.getMessages()));
                        //int a1 = Preference_RW.ff3_r();
                        //a1--;
                        //Preference_RW.ff3_w(a1);
                        BianQianShowAbilitySlice.this.contactArrays.remove(position);
                        BianQianShowAbilitySlice.this.contactAdapter.notifyDataChanged();
                        BianQianShowAbilitySlice.this.ShowDialog1("删除成功");
                        commonDialog.destroy();
                    }
                });
                component.findComponentById(ResourceTable.Id_bqcancel).setClickedListener(new Component.ClickedListener() {
                    @Override
                    public void onClick(Component v) {
                        commonDialog.destroy();
                    }
                });
                commonDialog.show();
                XLog.info(label, "当前设备类型为手机");
            } else if (localDeviceType == DeviceInfo.DeviceType.TABLET.value()) {
                Component component = LayoutScatter.getInstance(this.getContext())
                        .parse(ResourceTable.Layout_bianqian_3m, null, true);
                //commonDialog.setAutoClosable(true);
                commonDialog.setSize(860, 860);
                commonDialog.setContentCustomComponent(component);
                component.findComponentById(ResourceTable.Id_bqsure).setClickedListener(new Component.ClickedListener() {
                    @Override
                    public void onClick(Component v) {
                        if (position > BianQianShowAbilitySlice.this.contactArrays.size() - 1) {
                            BianQianShowAbilitySlice.this.ShowDialog("要删除的元素不存在");
                            return;
                        }
                        Contactor contactor = BianQianShowAbilitySlice.this.contactArrays.get(position);
                        liteOrm.delete(new WhereBuilder(Showmes.class)
                                .equals("title", contactor.getMessages()));
                        //int a1 = Preference_RW.ff3_r();
                        //a1--;
                        //Preference_RW.ff3_w(a1);
                        BianQianShowAbilitySlice.this.contactArrays.remove(position);
                        BianQianShowAbilitySlice.this.contactAdapter.notifyDataChanged();
                        BianQianShowAbilitySlice.this.ShowDialog1("删除成功");
                        commonDialog.destroy();
                    }
                });
                component.findComponentById(ResourceTable.Id_bqcancel).setClickedListener(new Component.ClickedListener() {
                    @Override
                    public void onClick(Component v) {
                        commonDialog.destroy();
                    }
                });
                commonDialog.show();
                XLog.info(label, "当前设备类型为平板");
            } else {
                XLog.warn(label, "暂不支持您的设备:(" + localDeviceInfo.getType() + ")");
                this.terminateAbility();
            }
        } catch (Exception e) {
            AGConnectCrash.getInstance().recordException(e);
            XLog.error(label, e.getMessage());
        }
    }

    /**
     * 展示
     *
     * @param position the position
     */
    @Override
    public void show(int position) {
        try {
            Contactor contactor = this.contactArrays.get(position);
            CommonDialog commonDialog = new CommonDialog(this);
            ohos.data.distributed.device.DeviceInfo localDeviceInfo = KvManagerFactory.getInstance()
                    .createKvManager(new KvManagerConfig((this))).getLocalDeviceInfo();
            int localDeviceType = Integer.parseInt(localDeviceInfo.getType());
            if (localDeviceType == DeviceInfo.DeviceType.PHONE.value()) {
                Component component = LayoutScatter.getInstance(this.getContext())
                        .parse(ResourceTable.Layout_bianqian_4m, null, true);
                commonDialog.setSize(950, 950);
                commonDialog.setContentCustomComponent(component);
                Text text1 = (Text) component.findComponentById(ResourceTable.Id_bqtext1);
                Text text2 = (Text) component.findComponentById(ResourceTable.Id_bqtext2);
                text2.setText(contactor.getTitles());
                text1.setText(contactor.getMessages());
                component.findComponentById(ResourceTable.Id_bqsure1).setClickedListener(new Component.ClickedListener() {
                    @Override
                    public void onClick(Component v) {
                        commonDialog.destroy();
                    }
                });
                commonDialog.show();
                XLog.info(label, "当前设备类型为手机");
            } else if (localDeviceType == DeviceInfo.DeviceType.TABLET.value()) {
                Component component = LayoutScatter.getInstance(this.getContext())
                        .parse(ResourceTable.Layout_bianqian_4t, null, true);
                commonDialog.setSize(1000, 1000);
                commonDialog.setContentCustomComponent(component);
                Text text1 = (Text) component.findComponentById(ResourceTable.Id_bqtext1);
                Text text2 = (Text) component.findComponentById(ResourceTable.Id_bqtext2);
                text2.setText(contactor.getTitles());
                text1.setText(contactor.getMessages());
                component.findComponentById(ResourceTable.Id_bqsure1).setClickedListener(new Component.ClickedListener() {
                    @Override
                    public void onClick(Component v) {
                        commonDialog.destroy();
                    }
                });
                commonDialog.show();
                XLog.info(label, "当前设备类型为平板");
            } else {
                XLog.warn(label, "暂不支持您的设备:(" + localDeviceInfo.getType() + ")");
                this.terminateAbility();
            }
        } catch (Exception e) {
            AGConnectCrash.getInstance().recordException(e);
            XLog.error(label, e.getMessage());
        }
    }

    /**
     * 分享
     *
     * @param position the position
     */
    @Override
    public void share(int position) {
        try {
            Contactor contactor = this.contactArrays.get(position);
            if (Preference_RW.ff4_r() == 0) {
                long a = Preference_RW.ff4_r();
                BianQianShowAbilitySlice.insert1(a, contactor.getMessages(), contactor.getTitles());
                a++;
                Preference_RW.ff4_w(a);
            } else {
                this.query1(contactor.getMessages());
                if (this.a8 == 666) BianQianShowAbilitySlice.update1(contactor.getMessages(), contactor.getTitles());
                else if (this.a8 == 999) {
                    long a = Preference_RW.ff4_r();
                    BianQianShowAbilitySlice.insert1(a, contactor.getMessages(), contactor.getTitles());
                    a++;
                    Preference_RW.ff4_w(a);
                } else XLog.info(label, "不可能！");
            }
            this.ShowDialog1("分享成功!");
        } catch (Exception e) {
            AGConnectCrash.getInstance().recordException(e);
            XLog.error(label, e.getMessage());
        }
    }

    /**
     * 退出
     *
     * @param keyCode  the key code
     * @param keyEvent the key event
     * @return boolean
     */
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent keyEvent) {
        if (keyCode == KeyEvent.KEY_BACK) {
            this.ShowDialog1("程序退出成功，感谢您的使用!");
            this.terminateAbility();
            return true;
        }
        return super.onKeyDown(keyCode, keyEvent);
    }

    /**
     * 移动
     *
     * @param component  the component
     * @param touchEvent the touch event
     * @return boolean
     */
    @Override
    public boolean onTouchEvent(Component component, TouchEvent touchEvent) {
        try {
            int action = touchEvent.getAction();

            ohos.global.resource.ResourceManager resManager = this.getResourceManager();
            try {
                text = resManager.getElement(ResourceTable.String_titles).getString();
                text1 = resManager.getElement(ResourceTable.String_titlex).getString();
            } catch (Exception e) {
                XLog.error(label, e.getMessage());
            }
            if (action == TouchEvent.PRIMARY_POINT_DOWN) {
                MmiPoint position = touchEvent.getPointerPosition(0);
                this.starx = position.getX();
                this.stary = position.getY();
            } else if (action == TouchEvent.PRIMARY_POINT_UP) {
                MmiPoint position = touchEvent.getPointerPosition(0);
                this.endx = position.getX();
                this.endy = position.getY();
                if (this.starx > this.endx && Math.abs(this.stary - this.endy) < 123 && Math.abs(this.starx - this.endx) > 167) {
                    /*无参--页面跳转开始*/
                    Intent intent7 = new Intent();
                    //present(new BianQianShareAbilitySlice(), intent7);
                    Operation operation = new Intent.OperationBuilder()
                            .withDeviceId("")
                            .withBundleName(this.getBundleName())
                            .withAbilityName("com.xcl.calculator.Ability.BianQian.BianQianShareAbility")
                            .build();// 通过Intent中的OperationBuilder类构造operation对象，指定设备标识（空串表示当前设备）、应用包名、Ability名称
                    intent7.setOperation(operation);// 把operation设置到intent中
                    this.startAbility(intent7);
                    /*页面跳转结束--无参*/
                    this.onBackPressed();
                    XLog.info(label, "左滑了");
                } else if (this.starx < this.endx && Math.abs(this.stary - this.endy) < 123 && Math.abs(this.starx - this.endx) > 167) {
                    /*无参--页面跳转开始*/
                    Intent intent = new Intent();
                    Operation operation = new Intent.OperationBuilder()
                            .withDeviceId("")
                            .withBundleName(this.getBundleName())
                            .withAbilityName("com.xcl.calculator.Ability.CaiDanAbility")
                            .build();// 通过Intent中的OperationBuilder类构造operation对象，指定设备标识（空串表示当前设备）、应用包名、Ability名称
                    intent.setOperation(operation);// 把operation设置到intent中
                    this.startAbility(intent);
                    this.onBackPressed();
                    XLog.info(label, "右滑了");
                } else if (this.stary > this.endy && Math.abs(this.starx - this.endx) < 123 && Math.abs(this.stary - this.endy) > 167)
                    XLog.info(label, "上滑了");
                else if (this.stary < this.endy && Math.abs(this.starx - this.endx) < 123 && Math.abs(this.stary - this.endy) > 167)
                    XLog.info(label, "下滑了");
                else XLog.info(label, "无效滑动（请直一点！）");
            } else XLog.info(label, "滑动中");
        } catch (Exception e) {
            AGConnectCrash.getInstance().recordException(e);
            XLog.error(label, e.getMessage());
        }
        return true;
    }

    /**
     * 查询
     *
     * @param a1 the a 1
     */
    private void query(String a1) {
        try {
            List<Showmes> books = liteOrm.query(new QueryBuilder<Showmes>(Showmes.class)
                    .columns(new String[]{"id", "title", "message"})
                    .distinct(true)
                    .whereEquals("title", a1));
            if (books.size() == 0) this.a6 = 999;
            else this.a6 = 666;
        } catch (Exception e) {
            AGConnectCrash.getInstance().recordException(e);
            XLog.error(label, e.getMessage());
        }
    }

    /**
     * 查询1
     *
     * @param a1 the a 1
     */
    private void query1(String a1) {
        try {
            List<Sharmes> books = liteOrm.query(new QueryBuilder<Sharmes>(Sharmes.class)
                    .columns(new String[]{"id", "title", "message"})
                    .distinct(true)
                    .whereEquals("title", a1));
            if (books.size() == 0) this.a8 = 999;
            else this.a8 = 666;
        } catch (Exception e) {
            AGConnectCrash.getInstance().recordException(e);
            XLog.error(label, e.getMessage());
        }
    }
}
